package com.corticon.dialogs.model;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;

import org.hibernate.validator.NotEmpty;

/**
 *
 * @author Yanglifan
 */
@MappedSuperclass
public class LookupBase extends AuditableEntity {

    private String code;
    private String name;
    private String description;
    protected UserGroup userGroup;

    public void init() {
        userGroup = userGroup == null ? new UserGroup() : userGroup;
    }

    @NotEmpty(message = "lookup.code.required")
    @Id
    @Column(name = "code", length = 30)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        if (code != null){
           code = code.length()>=30?code.substring(0, 30):code;
        }
        this.code = code;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name != null){
            name = name.length()>=255?name.substring(0, 255):name;
        }
       
        this.name = name;
    }

    @NotEmpty(message = "validate.description.notempty")
    @Column(name = "description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        if (description != null){
            description = description.length()>=255?description.substring(0, 255):description;
        }
        
        this.description = description;
    }

    @ManyToOne
    @JoinColumn(name = "usergroupassoc_groupid_oid")
    public UserGroup getUserGroup() {
        return userGroup;
    }

    public void setUserGroup(UserGroup userGroup) {
        this.userGroup = userGroup;
    }
}
